
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for change_password.
	''' </summary>
	Public Partial Class change_password
		Inherits BaseWebPage

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.CHANGE_PASSWORD_PAGE;


			If Constants.REGISTRATION_CONFIRM_PARAM_ACTION_VALUE.Equals(Request.Params(Constants.REGISTRATION_CONFIRM_PARAM_ACTION)) Then
				' Password was reset
				If AutoLogin(Request) Then
					rvCurrentpass.Visible = False
					txtCurrentpass.Visible = False
					lblCurrentPass.Visible = False
					cvCurrentPassValid.Visible = False
				End If
			End If

			Dim usr As User = LoggedUser
			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			' init page from XML
			Me.initPageTitles(Constants.CHANGE_PASSWORD, "", Form1, Nothing, Nothing)
			Me.initAdvertisements(Form1, Nothing)
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.cvCurrentPassValid.ServerValidate, AddressOf Me.cvCurrentPassValid_ServerValidate

		End Sub
#End Region

		Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			'if(Request.UrlReferrer.ToString() != null)
			'	Response.Redirect(Request.UrlReferrer.ToString());
			'else
			Response.Redirect(Constants.ACCOUNT_SETTINGS_PAGE)
		End Sub

		Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim success As Boolean = False
			Try
				Dim usr As User = LoggedUser
				Dim password As String = txtConfirmNewPass.Text.Trim()
				password = password.Substring(0, Math.Min(password.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))

				usr.Password = password
				usr.Save()
				success = True
			Catch generatedExceptionName As Exception
			End Try

			If success = True Then
				Response.Redirect(Constants.ACCOUNT_SETTINGS_PAGE)
			Else
				Response.Redirect(Constants.ERROR_PAGE + "?e=" + Constants.[ERROR])
			End If
		End Sub

		Private Sub cvCurrentPassValid_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			'User usr = LoggedUser;
'			if( usr.Password == txtCurrentpass.Text.Trim())
'				args.IsValid = true;
'			else
'				args.IsValid = false; 

			args.IsValid = True
		End Sub

		====================
        ' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
        Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
            Get
                Return Migrated_Form1
            End Get
        End Property
        'set { Migrated_Form1 = value; }
    End Class
End Namespace






